package page.result;

/**
 * @Auther lolineet
 * @Email tj.zhanghongwei@163.com
 * @Date 2021/11/24 14:15
 * @Description 分页返回值实体
 */
public class Result {
    /**
     * 结果码
     */
    private int code;
    /**
     * 信息描述
     */
    private String message;

    public Result(int code) {
        this.code = code;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result() {

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 成功
     */
    public static final int OK = 8200;
    /**
     * 参数错误
     */
    public static final int PARAMETER_ERROR = 8400;
    /**
     * 非法访问
     */
    public static final int UNAUTHORIZED = 8401;
    /**
     * 无数据
     */
    public static final int NO_DATA = 8402;
    /**
     * 没有权限
     */
    public static final int PERMISSION_DENIED = 8403;
    /**
     * 请求资源不可用
     */
    public static final int NOT_FOUND = 8404;
    /**
     * 操作失败
     */
    public static final int FAILURE = 8408;
    /**
     * 未知错误
     */
    public static final int UNKNOWN_ERROR = 8500;

    public static <T> Result0<T> ok() {
        return new Result0<T>(OK, "成功");
    }

    public static <T> Result0<T> ok(T data) {
        return new Result0<T>(OK, "成功", data);
    }

    public static <T> Result0<T> ok(String message) {
        return new Result0<T>(OK, message);
    }

    public static <T> Result0<T> ok(String message, T data) {
        return new Result0<T>(OK, message, data);
    }

    public static <T> Result0<T> ok(T data, Pagination page) {
        return new Result0<T>(OK, "成功", data, page);
    }


    public static <T> Result0<T> ok(String message, T data, Pagination page) {
        return new Result0<T>(OK, message, data, page);
    }

    public static <T> Result0<T> parameterError() {
        return new Result0<T>(PARAMETER_ERROR, "参数错误");
    }

    public static <T> Result0<T> parameterError(String message) {
        return new Result0<T>(PARAMETER_ERROR, message);
    }

    public static <T> Result0<T> failure() {
        return new Result0<T>(FAILURE, "操作失败");
    }

    public static <T> Result0<T> failure(String message) {
        return new Result0<T>(FAILURE, message);
    }

    public static <T> Result0<T> unknownError() {
        return new Result0<T>(UNKNOWN_ERROR, "未知错误");
    }

    public static <T> Result0<T> unknownError(String message) {
        return new Result0<T>(UNKNOWN_ERROR, message);
    }

    public static <T> Result0<T> noFound() {
        return new Result0<T>(NOT_FOUND, "请求资源不可用");
    }

    public static <T> Result0<T> noFound(String message) {
        return new Result0<T>(NOT_FOUND, message);
    }

    public static <T> Result0<T> unAuthorized() {
        return new Result0<T>(UNAUTHORIZED, "非法访问");
    }

    public static <T> Result0<T> unAuthorized(String message) {
        return new Result0<T>(UNAUTHORIZED, message);
    }

    public static <T> Result0<T> permissionDenied() {
        return new Result0<T>(PERMISSION_DENIED, "没有权限");
    }

    public static <T> Result0<T> permissionDenied(String message) {
        return new Result0<T>(PERMISSION_DENIED, message);
    }

    public static <T> Result0<T> noData() {
        return new Result0<T>(NO_DATA, "无数据");
    }

    public static <T> Result0<T> noData(String message) {
        return new Result0<T>(NO_DATA, message);
    }
}
